How can I fix the jQuery code for building a table with minimal changes